using Infrastructure.Attribute;
using Infrastructure.Extensions;
using JTZY.Model.Pay.Dto;
using JTZY.Model.Pay;
using JTZY.Repository;
using JTZY.Service.Pay.IPayService;

namespace JTZY.Service.Pay
{
    /// <summary>
    /// 微信支付配置Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(ICorecmswechatpayconfigService), ServiceLifetime = LifeTime.Transient)]
    public class CorecmswechatpayconfigService : BaseService<Corecmswechatpayconfig>, ICorecmswechatpayconfigService
    {
        /// <summary>
        /// 查询微信支付配置列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<CorecmswechatpayconfigDto> GetList(CorecmswechatpayconfigQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<Corecmswechatpayconfig, CorecmswechatpayconfigDto>(parm);

            return response;
        }


        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Corecmswechatpayconfig GetInfo(int Id)
        {
            var response = Queryable()
                .Where(x => x.Id == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加微信支付配置
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Corecmswechatpayconfig AddCorecmswechatpayconfig(Corecmswechatpayconfig model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改微信支付配置
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateCorecmswechatpayconfig(Corecmswechatpayconfig model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<Corecmswechatpayconfig> QueryExp(CorecmswechatpayconfigQueryDto parm)
        {
            var predicate = Expressionable.Create<Corecmswechatpayconfig>();

            return predicate;
        }
    }
}